package com.ruoyi.pcwl.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.pcwl.domain.AppCarousel;
import com.ruoyi.pcwl.domain.Article;
import com.ruoyi.pcwl.domain.ArticleContent;
import com.ruoyi.pcwl.mapper.AppCarouselMapper;
import com.ruoyi.pcwl.mapper.ArticleContentMapper;
import com.ruoyi.pcwl.service.IAppCarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;
import org.springframework.stereotype.Service;


/**
 * 轮播图信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-01-19
 */
@Service
public class AppCarouselServiceImpl extends ServiceImpl<AppCarouselMapper, AppCarousel> implements IAppCarouselService
{
    @Autowired
    private AppCarouselMapper appCarouselMapper;

    /**
     * 查询轮播图信息
     *
     * @param id 轮播图信息主键
     * @return 轮播图信息
     */
    @Override
    public AppCarousel selectAppCarouselById(Long id)
    {
        return appCarouselMapper.selectAppCarouselById(id);
    }

    /**
     * 查询轮播图信息列表
     *
     * @param appCarousel 轮播图信息
     * @return 轮播图信息
     */
    @Override
    public List<AppCarousel> selectAppCarouselList(AppCarousel appCarousel)
    {
        return appCarouselMapper.selectAppCarouselList(appCarousel);
    }

    /**
     * 新增轮播图信息
     *
     * @param appCarousel 轮播图信息
     * @return 结果
     */
    @Override
    public int insertAppCarousel(AppCarousel appCarousel)
    {
        return appCarouselMapper.insertAppCarousel(appCarousel);
    }

    /**
     * 修改轮播图信息
     *
     * @param appCarousel 轮播图信息
     * @return 结果
     */
    @Override
    public int updateAppCarousel(AppCarousel appCarousel)
    {
        return appCarouselMapper.updateAppCarousel(appCarousel);
    }

    /**
     * 批量删除轮播图信息
     *
     * @param ids 需要删除的轮播图信息主键
     * @return 结果
     */
    @Override
    public int deleteAppCarouselByIds(Long[] ids)
    {
        return appCarouselMapper.deleteAppCarouselByIds(ids);
    }

    /**
     * 删除轮播图信息信息
     *
     * @param id 轮播图信息主键
     * @return 结果
     */
    @Override
    public int deleteAppCarouselById(Long id)
    {
        return appCarouselMapper.deleteAppCarouselById(id);
    }

    @Override
    public IPage<AppCarousel> getArticlePage(Page<AppCarousel> appCarouselPage, AppCarousel appCarousel) {
        QueryWrapper<AppCarousel> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("sync_status","1");
//        queryWrapper.orderByDesc("publish_time");
//        baseMapper.selectList(queryWrapper);

        return baseMapper.selectPage(appCarouselPage,queryWrapper);
    }

    @Override
    public void publishCarousel(String id) {
        AppCarousel appCarousel = appCarouselMapper.selectAppCarouselById(Long.valueOf(id));
        if (appCarousel==null) {
            return;
        }
        if (appCarousel.getStatus().equals("1")) {
            appCarousel.setStatus("0");
        }else
            appCarousel.setStatus("1");
        appCarousel.setChangeDate(new java.util.Date());

        appCarouselMapper.updateAppCarousel(appCarousel);
    }

    @Override
    public List<AppCarousel> listPublishCarousel() {
        QueryWrapper<AppCarousel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status","1");
        queryWrapper.orderByDesc("create_date");
        List<AppCarousel> appCarousels = appCarouselMapper.selectList(queryWrapper);

        return appCarousels;
    }
}
